<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta charset="utf-8">
    <title>Home - JIFF Library Documentation</title>
    
    
    
    
    
    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
    <script src="scripts/nav.js" defer></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
  <div class="navicon"></div>
</label>

<label for="nav-trigger" class="overlay"></label>

<nav >
    
    <input type="text" id="nav-search" placeholder="Search" />
    
    <h2><a href="index.html">Home</a></h2><h2><a href="https://github.com/multiparty/jiff" target="_blank" class="menu-item" id="github_link" >Github Repo</a></h2><h2><a href="./intro.html" target="_self" class="menu-item" id="github_link" >Tutorial</a></h2><h2><a href="./contributing.html" target="_self" class="menu-item" id="github_link" >Contributing to JIFF</a></h2><h3>Classes</h3><ul><li><a href="GuardedSocket.html">GuardedSocket</a><ul class='methods'><li data-type='method'><a href="GuardedSocket.html#disconnect">disconnect</a></li><li data-type='method'><a href="GuardedSocket.html#is_empty">is_empty</a></li><li data-type='method'><a href="GuardedSocket.html#resend_mailbox">resend_mailbox</a></li><li data-type='method'><a href="GuardedSocket.html#safe_disconnect">safe_disconnect</a></li><li data-type='method'><a href="GuardedSocket.html#safe_emit">safe_emit</a></li></ul></li><li><a href="helpers.Deferred.html">Deferred</a><ul class='methods'><li data-type='method'><a href="helpers.Deferred.html#reject">reject</a></li><li data-type='method'><a href="helpers.Deferred.html#resolve">resolve</a></li></ul></li><li><a href="module-jiff-client-JIFFClient.html">JIFFClient</a><ul class='methods'><li data-type='method'><a href="module-jiff-client-JIFFClient.html#add_to_barriers">add_to_barriers</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#apply_extension">apply_extension</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#can_apply_extension">can_apply_extension</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#connect">connect</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#disconnect">disconnect</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#emit">emit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#end_barrier">end_barrier</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#executePreprocessing">executePreprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#extension_applied">extension_applied</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#free">free</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#from_crypto_provider">from_crypto_provider</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#gen_op_id">gen_op_id</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#gen_op_id2">gen_op_id2</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#gen_op_id2_preprocessing">gen_op_id2_preprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#gen_op_id_preprocessing">gen_op_id_preprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#get_preprocessing">get_preprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#has_extension">has_extension</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#has_preprocessing">has_preprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#internal_open">internal_open</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#internal_share">internal_share</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#isInitialized">isInitialized</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#isReady">isReady</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#listen">listen</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#open">open</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#open_array">open_array</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#preprocessing">preprocessing</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#preprocessingDaemon">preprocessingDaemon</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#receive_open">receive_open</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#remove_listener">remove_listener</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#reshare">reshare</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#seed_ids">seed_ids</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#share">share</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#share_array">share_array</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#start_barrier">start_barrier</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient.html#store_preprocessing">store_preprocessing</a></li></ul></li><li><a href="module-jiff-client-JIFFClient_SecretShare.html">SecretShare</a><ul class='methods'><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#add">add</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#bit_decomposition">bit_decomposition</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cadd">cadd</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cdiv">cdiv</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cdivfac">cdivfac</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#ceq">ceq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cgt">cgt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cgteqn">cgteqn</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#clt">clt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#clteq">clteq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cmult">cmult</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cneq">cneq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cor_bit">cor_bit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cpow">cpow</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#csub">csub</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#cxor_bit">cxor_bit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#div">div</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#eq">eq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#error">error</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#gt">gt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#gteq">gteq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#if_else">if_else</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#isConstant">isConstant</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#logLEAK">logLEAK</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#lt">lt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#lt_halfprime">lt_halfprime</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#lteq">lteq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#mult">mult</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#neq">neq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#not">not</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#open">open</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#or_bit">or_bit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#promise_handler">promise_handler</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#refresh">refresh</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sadd">sadd</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sdiv">sdiv</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#seq">seq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sgt">sgt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sgteq">sgteq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#slt">slt</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#slteq">slteq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#smod">smod</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#smult">smult</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#smult_bgw">smult_bgw</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sneq">sneq</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sor_bit">sor_bit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#ssub">ssub</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sub">sub</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#sxor_bit">sxor_bit</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#toString">toString</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#valueOf">valueOf</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#when_both_ready">when_both_ready</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#wThen">wThen</a></li><li data-type='method'><a href="module-jiff-client-JIFFClient_SecretShare.html#xor_bit">xor_bit</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-jiff-client.html">jiff-client</a></li></ul><h3>Namespaces</h3><ul><li><a href="bits.html">bits</a><ul class='methods'><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.bit_composition">jiffClient.protocols.bits.bit_composition</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cadd">jiffClient.protocols.bits.cadd</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cdivl">jiffClient.protocols.bits.cdivl</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cdivr">jiffClient.protocols.bits.cdivr</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.ceq">jiffClient.protocols.bits.ceq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cgt">jiffClient.protocols.bits.cgt</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cgteq">jiffClient.protocols.bits.cgteq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.clt">jiffClient.protocols.bits.clt</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.clteq">jiffClient.protocols.bits.clteq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cmult">jiffClient.protocols.bits.cmult</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.cneq">jiffClient.protocols.bits.cneq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.csubl">jiffClient.protocols.bits.csubl</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.csubr">jiffClient.protocols.bits.csubr</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.open">jiffClient.protocols.bits.open</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.rejection_sampling">jiffClient.protocols.bits.rejection_sampling</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.sadd">jiffClient.protocols.bits.sadd</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.sdiv">jiffClient.protocols.bits.sdiv</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.seq">jiffClient.protocols.bits.seq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.sgt">jiffClient.protocols.bits.sgt</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.sgteq">jiffClient.protocols.bits.sgteq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.share">jiffClient.protocols.bits.share</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.slt">jiffClient.protocols.bits.slt</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.slteq">jiffClient.protocols.bits.slteq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.smult">jiffClient.protocols.bits.smult</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.sneq">jiffClient.protocols.bits.sneq</a></li><li data-type='method'><a href="bits.html#.jiffClient.protocols.bits.ssub">jiffClient.protocols.bits.ssub</a></li></ul></li><li><a href="handlers.html">handlers</a><ul class='methods'><li data-type='method'><a href="handlers.html#.jiffClient.handlers.build_initialization_message">jiffClient.handlers.build_initialization_message</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.connected">jiffClient.handlers.connected</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.error">jiffClient.handlers.error</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.initialized">jiffClient.handlers.initialized</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.receive_crypto_provider">jiffClient.handlers.receive_crypto_provider</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.receive_custom">jiffClient.handlers.receive_custom</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.receive_open">jiffClient.handlers.receive_open</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.receive_share">jiffClient.handlers.receive_share</a></li><li data-type='method'><a href="handlers.html#.jiffClient.handlers.store_public_keys">jiffClient.handlers.store_public_keys</a></li></ul></li><li><a href="helpers.html">helpers</a><ul class='methods'><li data-type='method'><a href="helpers.html#.jiffClient.helpers.array_equals">jiffClient.helpers.array_equals</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.bits_to_number">jiffClient.helpers.bits_to_number</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.bLog">jiffClient.helpers.bLog</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.ceil">jiffClient.helpers.ceil</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.extended_gcd">jiffClient.helpers.extended_gcd</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.floor">jiffClient.helpers.floor</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.get_party_number">jiffClient.helpers.get_party_number</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.is_prime">jiffClient.helpers.is_prime</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.mod">jiffClient.helpers.mod</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.number_to_bits">jiffClient.helpers.number_to_bits</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.pow_mod">jiffClient.helpers.pow_mod</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.random">jiffClient.helpers.random</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.sort_ids">jiffClient.helpers.sort_ids</a></li><li data-type='method'><a href="helpers.html#.jiffClient.helpers.Zp_equals">jiffClient.helpers.Zp_equals</a></li></ul></li><li><a href="hooks.html">hooks</a><ul class='methods'><li data-type='method'><a href="hooks.html#.computeShares">computeShares</a></li><li data-type='method'><a href="hooks.html#.execute_array_hooks">execute_array_hooks</a></li></ul></li><li><a href="protocols.html">protocols</a><ul class='methods'><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_beaver_bgw">jiffClient.protocols.generate_beaver_bgw</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_random_and_quotient">jiffClient.protocols.generate_random_and_quotient</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_random_bit_bgw">jiffClient.protocols.generate_random_bit_bgw</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_random_bit_smult">jiffClient.protocols.generate_random_bit_smult</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_random_bits">jiffClient.protocols.generate_random_bits</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_random_number">jiffClient.protocols.generate_random_number</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.generate_zero">jiffClient.protocols.generate_zero</a></li><li data-type='method'><a href="protocols.html#.jiffClient.protocols.rejection_sampling">jiffClient.protocols.rejection_sampling</a></li></ul></li><li><a href="utils.html">utils</a><ul class='methods'><li data-type='method'><a href="utils.html#.jiffClient.utils.bit_combinator">jiffClient.utils.bit_combinator</a></li><li data-type='method'><a href="utils.html#.jiffClient.utils.many_secret_shares">jiffClient.utils.many_secret_shares</a></li><li data-type='method'><a href="utils.html#.jiffClient.utils.resolve_many_secrets">jiffClient.utils.resolve_many_secrets</a></li></ul></li></ul>
</nav>

<div id="main">
    

    



    


    <section class="package">
        <h3> </h3>		
    </section>









    



    <section class="readme">
        <article><h1>Client Library Hooks</h1>
<h2>Supported Hooks</h2>
<h3>Crypto Hooks:</h3>
<ul>
<li><code>generateKeyPair[Single]: function(instance)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li>Return: an object with two attributes: public_key and secret_key. Both keys must be in a format understandable
by dumpKey, encryptSign, and decryptSign hooks.</li>
</ul>
</li>
<li><code>dumpKey[Single]: function(instance, public_key)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>public_key</code>: the public key (as generated by generateKeyPair) which must be dumped to string.</li>
<li>Return: a string representing the public key.</li>
</ul>
</li>
<li><code>parseKey[Single]: function(instance, public_key_string)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>public_key_string</code>: string representation of the public key to be parsed (as generated by dumpKey).</li>
<li>Return: parsed public key in a format understandable by dumpKey, encryptSign, and decryptSign.</li>
</ul>
</li>
<li><code>encryptSign[Single]: function(instance, message, encryption_public_key, signing_private_key)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>message</code>: the message to encrypt <strong>always a string</strong></li>
<li><code>encryption_public_key</code>: public key to encrypt with (corresponding to the receiving party)</li>
<li><code>signing_private_key</code>: secret key to sign with (corresponding to this party)</li>
<li>Return: the signed cipher with any additional properties desired to be sent with it (tags, meta-info, etc.) <strong>as a JavaScript object</strong></li>
</ul>
</li>
<li><code>decryptSign[Single]: function(instance, cipher_text, decryption_secret_key, signing_public_key)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>cipher_text</code>: the cipher_text to decrypt, the format and type matches that returned by encryptSign <strong>must be a JavaScript object</strong></li>
<li><code>decryption_secret_key</code>: secret key to decrypt with (corresponding to this party)</li>
<li><code>signing_public_key</code>: public key to verify signature with (corresponding to sending party)</li>
<li>Throw: if signature did not check out correctly</li>
<li>Return: the decrypted message <strong>as a string</strong>.</li>
</ul>
</li>
</ul>
<h3>Share Hooks:</h3>
<ul>
<li><code>beforeShare[Array]: function(instance, secret, threshold, receivers_list, senders_list, Zp)</code>
<ul>
<li>Initially, parameters are as passed to <code>jiff_instance.share</code> in the client code:
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>secret</code>: the secret to share</li>
<li><code>threshold</code>: the threshold for sharing</li>
<li><code>receivers_list</code>: array of ids of receiving parties</li>
<li><code>senders_list</code>: array of ids of sending parties (parties that have secrets)</li>
<li><code>Zp</code>: the modulos</li>
</ul>
</li>
<li>Return: must return the (possibly modified) secret to share (to be used as the secret for subsequent hooks in the array).</li>
</ul>
</li>
<li><code>computeShares[Single]: function(instance, secret, parties_list, threshold, Zp)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>secret</code>: the secret to share</li>
<li><code>parties_list</code>: array of ids of parties for which to create shares of the secret</li>
<li><code>threshold</code>: the threshold for sharing</li>
<li><code>Zp</code>: the modulus</li>
<li>Return: must return a map from <code>party_id</code> to its corresponding share value (for every <code>party_id</code> in <code>parties_list</code>).</li>
</ul>
</li>
<li><code>afterComputeShare[Array]: function(instance, shares, threshold, receivers_list, senders_list, Zp)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>shares</code>: a map from party_id to the corresponding share value</li>
<li><code>threshold</code>: the threshold for sharing</li>
<li><code>receivers_list</code>: array of ids of receiving parties</li>
<li><code>senders_list</code>: array of ids of sending parties (parties that have secrets)</li>
<li><code>Zp</code>: the modulus</li>
<li>Return: must return a map from <code>party_id</code> to its corresponding share value (for every <code>party_id</code> in <code>receivers_list</code>).</li>
</ul>
</li>
<li><code>receiveShare[Array]: function(instance, sender_id, share)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>sender_id</code>: party_id of the sender</li>
<li><code>share</code>: the received share (after decryption)</li>
<li>Return: the share, possibly modified (this is used as share for the subsequent hooks in the array).</li>
</ul>
</li>
</ul>
<h3>Open Hooks:</h3>
<ul>
<li><code>beforeOpen[Array]: function(instance, share, parties)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>share</code>: the share to open {type: secret_share}</li>
<li><code>parties</code>: the parties that will receive the open</li>
<li>Return: the share to open, possibly modified (this is used as share for the subsequent hooks in the array).</li>
</ul>
</li>
<li><code>receiveOpen[Array]: function(instance, sender_id, share, Zp)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>sender_id</code>: party_id of the sender</li>
<li><code>share</code>: the received share (after decryption)</li>
<li><code>Zp</code>: the modulus</li>
<li>Return: the share, possibly modified (this is used as share for the subsequent hooks in the array).</li>
</ul>
</li>
<li><code>reconstructShare[Single]: function(instance, shares)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>shares</code>: a map from party_id to its corresponding object: <code>{&quot;value&quot;:share, &quot;sender_id&quot;:sender_id, &quot;Zp&quot;:Zp }</code></li>
<li>Return: the reconstructed secret.</li>
</ul>
</li>
<li><code>afterReconstructShare[Array]: function(instance, value)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>value</code>: the reconstructed value as returned by reconstructShare</li>
<li>Return: the reconstructed secret, possibly modified (this is used as value for the subsequent hooks in the array).</li>
</ul>
</li>
</ul>
<h3>Miscellaneous Hooks:</h3>
<ul>
<li><code>createSecretShare[Array]: function(instance, secret_share)</code>
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>secret_share</code>: the secret_share object as created by JIFF</li>
<li>Return: the <code>secret_share</code> object to be used by JIFF, possibly modified (this is used for the subsequent hooks in the array).</li>
</ul>
</li>
<li><code>beforeOperation[Array]: function(instance, label, msg)</code>
Called before serializing and sending messages for any operation.
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>label</code>: one of 'initialization', 'share', 'open', 'custom', 'crypto_provider', 'free', or 'disconnect'</li>
<li><code>msg</code>: the message received (parsed into a json object), the actual attributes in the object depend on which label it corresponds to</li>
<li>Return: the msg, including any modifications, that will sent out by this event.</li>
</ul>
</li>
<li><code>afterOperation[Array]: function(instance, label, msg)</code>
Called after receiving and parsing messages (but before handling them) for any event.
<ul>
<li><code>instance</code>: the JIFF instance</li>
<li><code>label</code>: one of 'initialization', 'public_keys', 'share', 'open', 'custom', 'crypto_provider', 'free', or 'disconnect'</li>
<li><code>msg</code>: the message received (parsed into a json object), the actual attributes in the object depend on which label it corresponds to</li>
<li>Return: the msg, including modifications, that will get passed into operation handlers.</li>
</ul>
</li>
</ul>
<h2>Example</h2>
<p>Hooks can be passed to an instance at creation time via the options object.</p>
<p>Single Hooks expect the value to be a function, while Array Hooks expect the value to be an array (even when only a single hooks is used).</p>
<pre class="prettyprint source lang-javascript"><code>var options = {};
options.hooks = {
  /* Example hooks. */
  'beforeShare': [
    function(instance, secret, threshold, receivers_list, senders_list, Zp) {
      /* Some code. */
      return modified_secret;
    } 
  ],
  'computeShares':
    function(secret, party_count, parties_list, threshold, Zp) {
      /* Some code. */
      return shares_map;
    }
};
var instance = make_jiff('hostname', 'computation_id', options);
</code></pre>
<h2>Flows Supported By Hooks</h2>
<p>Hooks allow to customize the following flows in JIFF without having to explicity modify JIFF's source code.</p>
<h3>Custom crypto libraries</h3>
<p>Allows using a different crypto library (e.g. for browser compatibility purposes), or disabling/changing the crypto primitives
all together. Note that the same/compatible implementation of these hooks must be passed to jiff-server, <em>and</em> any participating computation
instances created on the server side.</p>
<ol>
<li>hook: <code>generateKeyPair</code> called on initialization.</li>
<li>hook: <code>dumpKey</code> called to marshal the public key to a string that can be transmitted to other parties.</li>
<li>hook: <code>parseKey</code> called when a marshaled public key is received from some party to parse it.</li>
<li>hook: <code>encryptSign</code> called to sign and encrypt messages sent by this party for various operations, including share, open, and custom messages.</li>
<li>hook: <code>decryptSign</code> called to decrypt and verify messages received by this party.</li>
</ol>
<h3>Share flow</h3>
<p>Determines how shares are generated and sent to parties:</p>
<ol>
<li><code>jiff_instance.share</code></li>
<li>hook: <code>beforeShare</code></li>
<li>hook: <code>computeShare</code></li>
<li>hook: <code>afterComputeShare</code></li>
<li>hook: <code>encryptSign</code></li>
<li>send shares to parties</li>
<li>party receives share</li>
<li>hook: <code>decryptSign</code></li>
<li>hook: <code>receiveShare</code></li>
<li>resolve value into corresponding <code>secret_share</code> object</li>
</ol>
<p>Note that:</p>
<ul>
<li>the party may be receiving a share without sharing anything, in which case only steps 1 and 7-10 are executed;</li>
<li>the party may be sharing a value without receiving shares of anything, in which case only steps 1-6 are executed.</li>
</ul>
<h3>Open flow</h3>
<p>Determine show parties can open (reveal) a share and get the result:</p>
<ol>
<li><code>jiff_instance.open/share.open</code></li>
<li>hook: <code>beforeOpen</code></li>
<li>share is refreshed and refreshed value is used going forward</li>
<li>hook: <code>encryptSign</code></li>
<li>send share to parties</li>
<li>party receives share to open</li>
<li>hook: <code>decryptSign</code></li>
<li>hook: <code>receiveOpen</code></li>
<li>hook (once enough shares are received in step 8 above): <code>reconstructShare</code></li>
<li>hook: <code>afterReconstructShare</code></li>
<li>resolve reconstructed value into open promise/callback</li>
</ol>
<p>Alternatively, a party may receive the result for a share that it does not own, in which case the flow becomes:</p>
<ul>
<li><code>jiff_instance.receive_open</code></li>
<li>party receives share to open (step 6 from above sequence)</li>
<li>steps 7-11 from above sequence</li>
</ul>
<p>A party may also hold a share of the result but not receive the result, in which case only steps 1-5 of the original flow are executed.</p>
<h3>Creation of secret_share objects</h3>
<p>This flow is particularly useful when developing extensions for JIFF. This allows the user to modify the implementation of a <code>secret_share</code> object, including changing how operations are implemented (e.g. addition, multiplication, etc.), registering callbacks for when the share is computed, or adding additional operations:</p>
<ol>
<li>a share is created (e.g. by <code>jiff_instance.share</code> or by operating on shares)</li>
<li><code>new secret_share</code> is invoked</li>
<li>the default <code>secret_share</code> object is created</li>
<li>hook: <code>createSecretShare</code></li>
<li>returned <code>secret_share</code> object is used by JIFF</li>
</ol>
<h1>Server-Library Hooks</h1>
<p>The server library hooks work similarly to the client library. They are passed
in the hooks attribute of the options object similarly. Note that these hooks
are applied at the granularity of the entire server app, which includes all
computations, and all parties in them. If you have special roles or computations
that require specific hooks, you will either need to use a dedicated jiff-server instance
for them, or provide high level hooks which check the computation and party ids,
and execute the appropriate code for them.</p>
<h2>Supported Hooks</h2>
<h3>Crypto Hooks</h3>
<p>Exact match of the client library crypto hooks, except it does not include encryptSign or decryptSign, since server
does not decrypt/encrypt messages by default.</p>
<h3>Initialization Hooks</h3>
<ul>
<li><code>beforeInitialization</code></li>
<li><code>onInitializeUsedId</code> if party requests id that is already reserved: single hook.</li>
<li><code>afterInitialization</code></li>
</ul>
<h3>Free Party Ids tracking</h3>
<p>For tracking which ids are free and which are used</p>
<ul>
<li><code>trackFreeIds</code> initialize mailbox object, contains these functions:
<ul>
<li><code>is_free</code> check if party id is free</li>
<li><code>create_free</code> return (but do not reserve) a free party id</li>
<li><code>reserve</code> reserve a party id as not free</li>
</ul>
</li>
</ul>
<h3>Disconnect/Free Hooks</h3>
<ul>
<li><code>onDisconnect</code></li>
<li><code>beforeFree</code></li>
<li><code>afterFree</code></li>
</ul>
<h3>Mailbox Hooks</h3>
<p>For storing messages in mailboxes</p>
<ul>
<li><code>put_in_mailbox</code> put a message in mailbox</li>
<li><code>get_mailbox</code> get an array containing all messages in mailbox in order</li>
<li><code>remove_from_mailbox</code> remove message from mailbox by id returned by put_in_mailbox or get_mailbox</li>
<li><code>slice_mailbox</code> remove all messages up to and including given id</li>
</ul>
<h3>Miscellaneous Hooks</h3>
<ul>
<li><code>log</code></li>
<li><code>beforeOperation</code> after receiving but before servicing messages for share, open, custom, and crypto_provider. Server restful extension has an extra operation: 'poll'. Any errors raised in this hook cause the request to reject, and the error to be returned to the client.</li>
<li><code>afterOperation</code> after servicing but before sending output message for share, open, custom, and crypto_provider. Server restful extension has an extra operation: 'poll'. Any errors raised in this hook cause the request to reject, and the error to be returned to the client.</li>
<li><code>computeShares</code></li>
</ul></article>
    </section>






    
    
</div>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Jun 11 2020 11:54:53 GMT-0400 (Eastern Daylight Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>

<script src="scripts/search.js" defer></script>



</body>
</html>
